package cate.game.world.msg;

import cate.common.table.common.ParamRow;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBWorld;
import cate.game.res.MixResAdder;
import easy.java.practice.errorcode.EcException;
import org.apache.commons.lang3.StringUtils;

public class FavoriteRwdGetReq implements MsgInput {
    @Override
    public void execute(GameBody game, ClientContext cc) {
        final int RWD_ID = 92001;
        ParamRow row = game.table.common.param.get(RWD_ID);
        if(row == null) {
            throw new EcException("全局变量表中未找到ID="+RWD_ID+"的奖励配置");
        }
        if(StringUtils.isBlank(row.value)) {
            throw new EcException("全局变量表中ID="+RWD_ID+"的奖励为空");
        }
        if(cc.getRole().getWorld().other.favoriteGot) {
            throw new EcException("你已经领取过收藏有礼奖励了！").s();
        }
        cc.getRole().getWorld().other.favoriteGot = true;
        RoleWorldDataResp.doSend(cc.getRole());
        new MixResAdder().setRes(row.value).setOperation(GDOperation.FAVORITE_RWD).
                setOperationSub(RWD_ID).setDialogReward(true).exe(cc.getRole());
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBWorld.FAVORITE_RWD_GET_REQ;
    }
}
